package com.wandian.weather.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mylib.widget.shape.RoundTextView;
import com.mylib.widget.shape.RoundViewDelegate;
import com.wandian.weather.R;
import com.wandian.weather.bean.AqiBean;


public class WeatherIViewChildOne extends LinearLayout {
    private View rootView;
    private TextView tvWeek;
//    private TextView tvNightWeather;
    private TextView tvDayWeather;
    private TemperatureStyleOne ttvTemp;
    private TextView tvWindLevel;
    private TextView tvWind;
    private RoundTextView rtvAqi;
    private ImageView ivNightWeather;

    public WeatherIViewChildOne(Context context) {
        this(context, null);
    }

    public WeatherIViewChildOne(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public WeatherIViewChildOne(Context context, AttributeSet attrs, int defStyleAttr) {
        this(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        rootView = LayoutInflater.from(context).inflate(R.layout.weather_view_one_item, null);
        tvWeek = (TextView) rootView.findViewById(R.id.tv_week);
//        tvNightWeather = (TextView) rootView.findViewById(R.id.tv_night_weather);
        tvDayWeather = (TextView) rootView.findViewById(R.id.tv_day_weather);
        ttvTemp = (TemperatureStyleOne) rootView.findViewById(R.id.ttv_day);
        rtvAqi = (RoundTextView) rootView.findViewById(R.id.rtv_aqi);
        tvWindLevel = (TextView) rootView.findViewById(R.id.tv_wind_level);
        tvWind = (TextView) rootView.findViewById(R.id.tv_wind);
        ivNightWeather = (ImageView) rootView.findViewById(R.id.iv_night_weather);
        rootView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        addView(rootView);
    }

    public void setWind(String wind) {
        if (tvWind != null)
            tvWind.setText(wind);
    }

    public void setWeek(String week) {
        if (tvWeek != null)
            tvWeek.setText(week);
    }

    public int getTempX() {
        if (ttvTemp != null)
            return (int) ttvTemp.getX();
        return 0;
    }

    public int getTempY() {
        if (ttvTemp != null)
            return (int) ttvTemp.getY();
        return 0;
    }

    public void setNightWeather(String nightWeather) {
//        if (tvNightWeather != null)
//            tvNightWeather.setText(nightWeather);

    }
    public void setDayWeather(String dayWeather) {
        if (dayWeather != null)
            tvDayWeather.setText(dayWeather);

    }


    public void setAqi(AqiBean aqiBean, boolean isWorld){
        if(isWorld){
            rtvAqi.setVisibility(GONE);
        }
        if(aqiBean != null){
            rtvAqi.setText(aqiBean.getAqiName());
            RoundViewDelegate delegate = rtvAqi.getDelegate();
            delegate.setBackgroundColor(aqiBean.getAqiColor());
        }
    }

    public void setWindLevel(String windLevel) {
        if (tvWindLevel != null)
            tvWindLevel.setText(windLevel);
    }

    public void setDayTemp(int dayTemp) {
        if (ttvTemp != null)
            ttvTemp.setTemperatureDay(dayTemp);
    }

    public void setNightImg(int resId) {
        if (ivNightWeather != null){
            ivNightWeather.setImageResource(resId);
        }

    }

    public void setMaxTemp(int max) {
        if (ttvTemp != null)
            ttvTemp.setMaxTemp(max);
    }

    public void setMinTemp(int min) {
        if (ttvTemp != null) {
            ttvTemp.setMinTemp(min);
        }
    }
}
